home *** CD-ROM | disk | FTP | other *** search
- {converts intel hex file into TP inline hex format}
- {MAKEHEX V1.01 Copyright 1989 Michael Day as of 16 April 1989}
- {all rights reserved}
- program makehex;
- uses dos;
- const MaxSize = 20000;
- var fr,fw:file;
- f1,f2:string;
- hcount,ri,wi,wc,result : integer;
- tempr:array[0..MaxSize] of byte;
- tempw:array[0..MaxSize] of byte;
-
- function hexnum(H,L:byte):integer;
- var temp:integer;
- begin
- if H > $39 then
- temp := ((H - 7) shl 4) and $f0
- else
- temp := (H shl 4) and $f0;
- if L > $39 then
- temp := temp + ((L - 7) and $f)
- else
- temp := temp + (L and $f);
- hexnum := temp;
- end;
-
- begin
- fillchar(fr,sizeof(fr),0);
- fillchar(fw,sizeof(fw),0);
- if paramcount < 2 then
- begin
- writeln('** Error: Insufficent data given **');
- writeln('Format is: MAKEHEX INFILE.HEX OUTFILE.PAS');
- halt(1);
- end;
- f1 := ParamStr(1);
- f2 := ParamStr(2);
- writeln('Reading:',f1,' --> Creating:',f2);
-
- assign(fr,f1);
- reset(fr,1);
- if FileSize(fr) > (maxsize) then
- begin
- writeln('Error:',f1,' <- File is too big to convert');
- Halt(3);
- end;
- blockread(fr,tempr,MaxSize,result);
- close(fr);
- assign(fw,f2);
- rewrite(fw,1);
-
- ri := 0;
- wi := 0;
- wc := 0;
- while ri <= result do
- begin
- while (tempr[ri] <> byte(':')) and (ri <= result) do inc(ri);
- if ri <= result then
- begin
- hcount := hexnum(tempr[ri+1],tempr[ri+2]);
- inc(ri,9);
- while (ri <= result) and (hcount > 0) do
- begin
- tempw[wi] := byte('$');
- tempw[wi+1] := tempr[ri];
- tempw[wi+2] := tempr[ri+1];
- tempw[wi+3] := byte(',');
- inc(wi,4);
- inc(ri,2);
- dec(hcount);
- inc(wc);
- if (wc and $f) = 0 then
- begin
- tempw[wi] := 13;
- tempw[wi+1] := 10;
- inc(wi,2);
- end;
- end;
- end;
- end;
- tempw[wi] := 13;
- tempw[wi+1] := 10;
- inc(wi,2);
- blockwrite(fw,tempw,wi,result);
- close(fw);
- writeln('* Done *');
- end.
-